<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>增加系统用户</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}" media="all">
    <script type="text/javascript" th:src="@{/static/js/jquery-3.js}"></script>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>增加系统用户</legend>
</fieldset>

<div class="layui-form-item">
    <label class="layui-form-label">用户昵称&nbsp;:</label>
    <div class="layui-input-block">
        <input type="text" name='nick' id="nick" lay-verify="required" lay-reqtext="用户昵称为必填项" placeholder="请输入用户昵称" autocomplete="off"  style="width:500px;"   class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">用户名&nbsp;:</label>
    <div class="layui-input-block">
        <input type="text" name='username' id="username" lay-verify="required" lay-reqtext="用户名为必填项" placeholder="请输入用户名" autocomplete="off"  style="width:500px;"   class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <label class="layui-form-label">密码&nbsp;:</label>
    <div class="layui-input-block">
        <input type="password" name='password' id="password" lay-verify="required" lay-reqtext="密码为必填项" placeholder="请输入密码" autocomplete="off"  style="width:500px;"   class="layui-input" >
    </div>
</div>

<div class="layui-form-item">
    <div class="layui-input-block">
        <button type="submit" class="layui-btn" lay-submit="" lay-filter="subBtn">提交</button>
    </div>
</div>

<script th:src="@{/static/layui/layui.js}" charset="utf-8"></script>

<script>

    var basePath="/";

    layui.use(['form'],function () {
        var thisIndex = parent.layer.getFrameIndex(window.name);
        var form = layui.form;
        var parentLayer = parent.layer;
        form.on("submit(subBtn)",function () {
            var obj = {
                nick: $("#nick").val(),
                username: $("#username").val(),
                password: $("#password").val()
            };
            console.log(obj);
            parentLayer.close(thisIndex);
            $.post(basePath+"sys/add",obj,function (data) {
                if(data.code == 9999){
                    parentLayer.msg("添加失败，该用户已经存在",{
                        icon: 1,
                        time: 10000
                    });
                }else{
                    parentLayer.msg("添加成功",{
                        icon: 1,
                        time: 2000
                    });
                }
                parent.location.reload();
            },"json");

        })
    })

</script>

</body>
</html>